package com.example.chenhaosblog.controller;

import com.example.chenhaosblog.base.BaseController;

import com.example.chenhaosblog.service.DemoService;
import com.example.chenhaosblog.utils.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * demo 模块
 */
@Controller
@RequestMapping("/UploadController")
public class UploadController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(DemoController.class);
	@Autowired
	private DemoService demoService;


	@Value("${imgUplode.url}")
	private String upimg;//图片上传路径
	@Value("${getImg.url}")
	private String getimg;//图片访问路径

/**\
 * 上传
 *MultipartFile file,
 */
@RequestMapping("/uploadFile")
@ResponseBody
public PageData uploadFile (@RequestParam("file") MultipartFile file) throws Exception{
		//操作
	//返回结果
	PageData result = new PageData();
	//参数
	PageData pageData = getPageData();
	try {

		String filename=FileUpload.fileUploadNew(file,upimg);



		result.put("code",0);
		result.put("title", "对对对");
		pageData.put("src",getimg+filename);
		pageData.put("msg", "上传成功");
		result.put("data", pageData);


	} catch (Exception e) {
		throw new Exception(e.toString());
	}
	return result;
}


	
	
}
